use "Data.dta", clear

* reversing support var for abortion
replace support = 2 if support==1 & topic==7
replace support = 1 if support==0 & topic==7
replace support = 0 if support==2 & topic==7

* college dummy
recode edu3 (1=0) (2/3=1), g(college)



** Tables for Appendix B

* Table B1: balance testing
preserve
duplicates drop respondent_id, force

recode race (9=1) (2/8=0), g(white)
recode race (2=1) (1 3 4 5 6 7 8 9=0), g(asian)
recode race (3=1) (2 4 5 6 7 8 9=0), g(black)
recode race (4=1) (2 3 5 6 7 8 9=0), g(latino)

recode pid (2=1) (3 4 5=0), g(democrat)
recode pid (3=1) (2 4 5=0), g(independent)
recode pid (5=1) (2 3 4=0), g(republican)

ttest age, by(treatment)
ttest female, by(treatment)
ttest college, by(treatment) 
ttest income, by(treatment)
ttest white, by(treatment) 
ttest black, by(treatment) 
ttest asian, by(treatment) 
ttest latino, by(treatment)
ttest voter, by(treatment)
ttest democrat, by(treatment) 
ttest independent, by(treatment) 
ttest republican, by(treatment) 
ttest lib_cons, by(treatment)
ttest pol_know, by(treatment)
restore 


** Figures for Appendix E


* Figure E1
reg dk i.treatment##i.topic i.round, cluster(respondent_id)
margins, dydx(treatment) over(topic)

marginsplot, xlabel(1 `""Infrastructure" "bill""' 2 `""Minimum" "wage""' 3 "Estate tax" 4 `""Capital gains" "tax""' 5 `""Border" "security""' 6 `""Transgender in" "military""' 7 "Abortion" 8 `""Covid" "vaccines""' , nogrid labsize(medsmall) labcolor(gray)) plotopts(msym(O) msize(medlarge) mlcolor("black") mfcolor("black")) recast(scatter) recastci(rspike) ci1opt(color(black) lwidth(medthick)) xsize(10) scheme(plotplain) xtitle("") ytitle("Treatment effect", size(medlarge) color("gray")) title("") ylabel(0(.1).4, labsize(medsmall) labcolor(gray)) xscale(r(0.8 8.2))

graph export "figureE1.pdf",  replace


* Figure E2a: education
reg dk i.treatment##i.re_edu i.topic i.round, cluster(respondent_id)

margins, dydx(treatment) at(re_edu=(2(1)6))
marginsplot, xlabel(2 "High school or less" 3 "Some college" 4 "2-year college degree" 5 "4-year college degree" 6 `""Postgraduate" "degree""', nogrid labsize(medsmall) labcolor(gray)) plotopts(msym(O) msize(medlarge) mlcolor("black") mfcolor("black")) recast(scatter) recastci(rspike) ci1opt(color(black) lwidth(medthick)) xsize(10) scheme(plotplain) xtitle("") ytitle("Treatment effect", size(medlarge) color("gray")) title("{bf: A}", position(11) size(large)) ylabel(0(.1).32, labsize(medsmall) labcolor(gray)) xscale(r(1.8 6.2))
	
	graph export "figureE2a.pdf",  replace

* Figure E2b: income
reg dk i.treatment##i.inc13 i.topic i.round, cluster(respondent_id)
	
margins, dydx(treatment) at(inc13=(1(1)13))
marginsplot, xlabel(1 "<$10k" 2 "$10k-$20k" 3 "$20k-$30k" 4 "$30k-$40k" 5 "$40k-$50k" 6 "$50k-$60k" 7 "$60k-$70k" 8 "$70k-$80k" 9 "$80k-$90k" 10 "$90k-$100k" 11 "$100k-$150k" 12 "$150k-$200k" 13 ">$200k", nogrid angle(45) labsize(medsmall) labcolor(gray)) plotopts(msym(O) msize(medlarge) mlcolor("black") mfcolor("black")) recast(scatter) recastci(rspike) ci1opt(color(black) lwidth(medthick)) xsize(10) scheme(plotplain) xtitle("") ytitle("Treatment effect", size(medlarge) color("gray")) title("{bf: B}", position(11) size(large)) ylabel(0(.1).32, labsize(medsmall) labcolor(gray)) xscale(r(0.8 13.2))

graph export "figureE2b.pdf",  replace


*Figure E2c:  gender
reg dk i.treatment##i.female i.topic i.round, cluster(respondent_id)

margins, dydx(treatment) at(female=(0 1))
marginsplot, xlabel(0 "Men" 1 "Women", nogrid labsize(medsmall) labcolor(gray)) plotopts(msym(O) msize(medlarge) mlcolor("black") mfcolor("black")) recast(scatter) recastci(rspike) ci1opt(color(black) lwidth(medthick)) xsize(4) scheme(plotplain) xtitle("") ytitle("Treatment effect", size(medlarge) color("gray")) title("{bf: C}", position(11) size(large)) ylabel(0(.1).32, labsize(medsmall) labcolor(gray)) xscale(r(-0.2 1.2))

graph export "figureE2c.pdf",  replace


* Figure E2d:  voters
reg dk i.treatment##i.voter i.topic i.round, cluster(respondent_id)

margins, dydx(treatment) at(voter=(0 1))
marginsplot, xlabel(0 "Non-voters" 1 "Voters", nogrid labsize(medsmall) labcolor(gray)) plotopts(msym(O) msize(medlarge) mlcolor("black") mfcolor("black")) recast(scatter) recastci(rspike) ci1opt(color(black) lwidth(medthick)) xsize(4) scheme(plotplain) xtitle("") ytitle("Treatment effect", size(medlarge) color("gray")) title("{bf: D}", position(11) size(large)) ylabel(0(.1).32, labsize(medsmall) labcolor(gray)) xscale(r(-0.2 1.2))
	
graph export "figureE2d.pdf",  replace
	
* Figure E3a: education


foreach n of numlist 1/8 {
reg support i.treatment##i.college i.round if topic==`n', cluster(respondent_id)
margins, at(college=(0 1) treatment=(0 1)) saving("h2b_edu_topic`n'", replace)

preserve
use "h2b_edu_topic`n'", clear
g topic=`n'
save "h2b_edu_topic`n'", replace
restore

}

preserve
use "h2b_edu_topic1", clear

foreach n of numlist 2/8 {
append using "h2b_edu_topic`n'"
}

label define topiclab_alt2 1 "Infrastructure" 2 "Min wage" 3 "Estate tax" 4 "CG tax" 5 "Border sec" 6 "Transgender" 7 "Abortion" 8 "Covid"
label values topic topiclab_alt2

* add a little "jitter"
replace _at2=_at2+1
replace _at2=.90 if _at2==1 & _at1==0
replace _at2=1.90 if _at2==2 & _at1==0


replace _at2=1.1 if _at2==1 & _at1==1
replace _at2=2.1 if _at2==2 & _at1==1

twoway ///
(scatter _margin _at2 if _at1==0, msymbol(O) mcolor(black) lcolor(black)) ///
(scatter _margin _at2 if _at1==1, msymbol(O) mcolor(gray) lcolor(gray) lpattern(solid)) ///
(rspike _ci_lb _ci_ub _at2 if _at1==0,  lcolor(black)  lwidth(medthick)) ///
(rspike _ci_lb _ci_ub _at2 if _at1==1, lcolor(gray)  lwidth(medthick)), ///
by(topic, r(1) note("") title("{bf: A}", size(large) position(11))) subtitle(,  size(medsmall)) ///
scheme(plotplain) yline(.5) legend(pos(6) col(2) title("")  order(1 2) label(1 "No DK-option") label(2 "DK-option")) xlabel(1 "No" 2 "Yes", labsize(medsmall)  labcolor(gray) tlength(0.5)) xtick(1 2) ylabel(0.3(.1)0.9, labsize(medsmall) labcolor(gray)) xtitle("College degree", size(medsmall) color(gray)) ytitle("Policy support", size(medsmall) color(gray)) xsize(8) 
restore

graph export "figureE3a.pdf",  replace

	
	
* Figure E3b: income

foreach n of numlist 1/8 {
reg support i.treatment##i.inc3 i.round if topic==`n', cluster(respondent_id)
margins, at(inc3=(1 2 3) treatment=(0 1)) saving("h2b_inc_topic`n'", replace)

preserve
use "h2b_inc_topic`n'", clear
g topic=`n'
save "h2b_inc_topic`n'", replace
restore

}

preserve
use "h2b_inc_topic1", clear

foreach n of numlist 2/8 {
append using "h2b_inc_topic`n'"
}

label define topiclab_alt2 1 "Infrastructure" 2 "Min wage" 3 "Estate tax" 4 "CG tax" 5 "Border sec" 6 "Transgender" 7 "Abortion" 8 "Covid"
label values topic topiclab_alt2

* add a little "jitter"
replace _at2=.90 if _at2==1 & _at1==0
replace _at2=1.90 if _at2==2 & _at1==0
replace _at2=2.90 if _at2==3 & _at1==0


replace _at2=1.1 if _at2==1 & _at1==1
replace _at2=2.1 if _at2==2 & _at1==1
replace _at2=3.1 if _at2==3 & _at1==1

twoway ///
(scatter _margin _at2 if _at1==0, msymbol(O) mcolor(black) lcolor(black)) ///
(scatter _margin _at2 if _at1==1, msymbol(O) mcolor(gray) lcolor(gray) lpattern(solid)) ///
(rspike _ci_lb _ci_ub _at2 if _at1==0,  lcolor(black)  lwidth(medthick)) ///
(rspike _ci_lb _ci_ub _at2 if _at1==1, lcolor(gray)  lwidth(medthick)), ///
by(topic, r(1) note("") title("{bf: B}", size(large) position(11))) subtitle(,  size(medsmall)) ///
scheme(plotplain) yline(.5) legend(pos(6) col(2) title("")  order(1 2) label(1 "No DK-option") label(2 "DK-option")) xlabel(1 "Low" 2 "Med" 3 "High", labsize(medsmall)  labcolor(gray) tlength(0.5)) xtick(1 2 3) ylabel(0.3(.1)0.9, labsize(medsmall) labcolor(gray)) xtitle("Income", size(medsmall) color(gray)) ytitle("Policy support", size(medsmall) color(gray)) xsize(8)

graph export "figureE3b.pdf",  replace
restore



* Figure E3c: gender
foreach n of numlist 1/8 {
reg support i.treatment##i.female i.round if topic==`n', cluster(respondent_id)
margins, at(female=(0 1) treatment=(0 1)) saving("h2b_female_topic`n'", replace)

preserve
use "h2b_female_topic`n'", clear
g topic=`n'
save "h2b_female_topic`n'", replace
restore

}

preserve
use "h2b_female_topic1", clear

foreach n of numlist 2/8 {
append using "h2b_female_topic`n'"
}

label define topiclab_alt2 1 "Infrastructure" 2 "Min wage" 3 "Estate tax" 4 "CG tax" 5 "Border sec" 6 "Transgender" 7 "Abortion" 8 "Covid"
label values topic topiclab_alt2

* add a little "jitter"
replace _at2=_at2+1
replace _at2=.90 if _at2==1 & _at1==0
replace _at2=1.90 if _at2==2 & _at1==0


replace _at2=1.1 if _at2==1 & _at1==1
replace _at2=2.1 if _at2==2 & _at1==1

twoway ///
(scatter _margin _at2 if _at1==0, msymbol(O) mcolor(black) lcolor(black)) ///
(scatter _margin _at2 if _at1==1, msymbol(O) mcolor(gray) lcolor(gray) lpattern(solid)) ///
(rspike _ci_lb _ci_ub _at2 if _at1==0,  lcolor(black)  lwidth(medthick)) ///
(rspike _ci_lb _ci_ub _at2 if _at1==1, lcolor(gray)  lwidth(medthick)), ///
by(topic, r(1) note("") title("{bf: C}", size(large) position(11))) subtitle(,  size(medsmall)) ///
scheme(plotplain) yline(.5) legend(pos(6) col(2) title("")  order(1 2) label(1 "No DK-option") label(2 "DK-option")) xlabel(1 "Men" 2 "Women", labsize(medsmall)  labcolor(gray) tlength(0.5)) xtick(1 2) ylabel(0.3(.1)0.9, labsize(medsmall) labcolor(gray)) xtitle("", size(medsmall) color(gray)) ytitle("Policy support", size(medsmall) color(gray)) xsize(8) 


graph export "figureE3c.pdf",  replace
restore



* Figure E3d: voter
foreach n of numlist 1/8 {
reg support i.treatment##i.voter i.round if topic==`n', cluster(respondent_id)
margins, at(voter=(0 1) treatment=(0 1)) saving("h2b_voter_topic`n'", replace)

preserve
use "h2b_voter_topic`n'", clear
g topic=`n'
save "h2b_voter_topic`n'", replace
restore

}

preserve
use "h2b_voter_topic1", clear

foreach n of numlist 2/8 {
append using "h2b_voter_topic`n'"
}

label define topiclab_alt2 1 "Infrastructure" 2 "Min wage" 3 "Estate tax" 4 "CG tax" 5 "Border sec" 6 "Transgender" 7 "Abortion" 8 "Covid"
label values topic topiclab_alt2

* add a little "jitter"
replace _at2=_at2+1
replace _at2=.90 if _at2==1 & _at1==0
replace _at2=1.90 if _at2==2 & _at1==0


replace _at2=1.1 if _at2==1 & _at1==1
replace _at2=2.1 if _at2==2 & _at1==1

twoway ///
(scatter _margin _at2 if _at1==0, msymbol(O) mcolor(black) lcolor(black)) ///
(scatter _margin _at2 if _at1==1, msymbol(O) mcolor(gray) lcolor(gray) lpattern(solid)) ///
(rspike _ci_lb _ci_ub _at2 if _at1==0,  lcolor(black)  lwidth(medthick)) ///
(rspike _ci_lb _ci_ub _at2 if _at1==1, lcolor(gray)  lwidth(medthick)), ///
by(topic, r(1) note("") title("{bf: D}", size(large) position(11))) subtitle(,  size(medsmall)) ///
scheme(plotplain) yline(.5) legend(pos(6) col(2) title("")  order(1 2) label(1 "No DK-option") label(2 "DK-option")) xlabel(1 "No" 2 "Yes", labsize(medsmall)  labcolor(gray) tlength(0.5)) xtick(1 2) ylabel(0.3(.1)0.9, labsize(medsmall) labcolor(gray)) xtitle("Voter", size(medsmall) color(gray)) ytitle("Policy support", size(medsmall) color(gray)) xsize(8) 

graph export "figureE3d.pdf",  replace
restore



* Figure E4a: college
preserve

foreach n of numlist 1/8 {
reg support i.treatment##i.college i.round if topic==`n', cluster(respondent_id)
margins, at(college=(0 1) treatment=(0 1)) post
xlincom 1._at-2._at, post

esttab, ci

mat ci`n'= r(coefs)

reg support i.treatment##i.college i.round if topic==`n', cluster(respondent_id)
margins, at(college=(0 1) treatment=(0 1)) post
xlincom 3._at-4._at, post

esttab, ci

mat cit`n'= r(coefs)


reg support i.treatment##i.college i.round if topic==`n', cluster(respondent_id)
margins, at(college=(0 1) treatment=(0 1)) post
xlincom ((1._at-2._at)-(3._at-4._at)), post

esttab, se

mat did`n'= r(coefs)

}
mat ci = ci1\ci2\ci3\ci4\ci5\ci6\ci7\ci8\cit1\cit2\cit3\cit4\cit5\cit6\cit7\cit8

mat list ci

sort respondent_id topic

keep in 1/16

keep topic topic2

g treatment=0 
replace treatment=1 in 9/16

svmat double ci, name(temp)
ren temp1 margin
ren temp2 lb
ren temp3 ub
drop temp4

mat did = did1\did2\did3\did4\did5\did6\did7\did8

mat list did

svmat double did, name(temp)
ren temp1 did_est
ren temp2 did_se
ren temp3 did_p

label define topiclab_alt2 1 "Infrastructure" 2 "Min wage" 3 "Estate tax" 4 "CG tax" 5 "Border sec" 6 "Transgender" 7 "Abortion" 8 "Covid"
label values topic topiclab_alt2

sort topic treatment
g hline=ub+0.03 if treatment==1
replace hline=hline[_n+1] if hline==.

g temp=ub+0.03 if treatment==0
replace temp=temp[_n-1] if temp==.

replace hline=temp if topic==2 | topic==3 | topic==8

drop temp 

g dropl=hline
replace dropl=hline+0.0012 if treatment==0
replace dropl=hline-0.01 if treatment==1

** labels
* slope coefficient
su did_est if treatment==0 & topic==1
local margin_3f : di %9.3f r(mean)
di `margin_3f'
g dydx_t="`margin_3f'" if treatment==0 & topic==1

foreach n of numlist 2/8 {
	su did_est if treatment==0 & topic== `n'
	local margin_3f : di %9.3f r(mean)
	replace dydx_t="`margin_3f'" if treatment==0 & topic== `n'
}


* se
su did_se if treatment==0 & topic== 1
local margin_3f : di %9.3f r(mean)
di `margin_3f'
g se_t="(`margin_3f')" if treatment==0 & topic==1


foreach n of numlist 2/8 {
	su did_se if treatment==0 & topic== `n'
	local margin_3f : di %9.3f r(mean)
	replace se_t="(`margin_3f')" if treatment==0 & topic== `n'
}

replace se_t = subinstr(se_t, " ", "", .)

g lab_t=dydx_t+" "+se_t

replace dydx_t=dydx_t+"*" if did_p<0.05
replace dydx_t=dydx_t+"+" if did_p<0.1 & did_p>0.05

g z=0
g o=1
g x=0.08
g x2=0.14
g y_h=hline+0.04
g y_h2=hline+0.02

twoway ///
(scatter margin treatment if treatment==0, msymbol(O) mcolor(black) lcolor(black)) ///
(scatter margin treatment if treatment==1, msymbol(O) mcolor(gray) lcolor(gray) lpattern(solid)) ///
(rspike lb ub treatment if treatment==0,  lcolor(black)  lwidth(medthick)) ///
(rspike lb ub treatment if treatment==1, lcolor(gray)  lwidth(medthick)) ///
 (line  hline treatment ,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (line  dropl z,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (line  dropl o,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (scatter y_h x2, ms(none) mla(dydx_t) mlabcolor(black) mlabsize(medsmall)) ///
 (scatter y_h2 x, ms(none) mla(se_t) mlabcolor(black) mlabsize(medsmall)), ///
by(topic, r(1) legend(off) note("") title("A: College degree", size(large) position(11))) subtitle(,  size(medsmall)) ///
scheme(plotplain) yline(.5) xtick(0 1) xscale(r(-0.2 1.2)) xlabel(0 "Control" 1 "Treat.", labsize(medsmall)  labcolor(gray) tlength(0.5)) ylabel(-0.3(.1)0.3, labsize(medsmall) labcolor(gray) format(%3.1f)) xtitle("", size(medsmall) color(gray)) ytitle("", size(medsmall) color(gray)) xsize(8)


graph export "figureE4a.pdf",  replace
restore



* Figure E4b: income

preserve
foreach n of numlist 1/8 {
reg support i.treatment##i.inc3 i.round if topic==`n', cluster(respondent_id)
margins, at(inc3=(1 2 3) treatment=(0 1)) post
xlincom 1._at-3._at, post

esttab, ci

mat ci`n'= r(coefs)

reg support i.treatment##i.inc3 i.round if topic==`n', cluster(respondent_id)
margins, at(inc3=(1 2 3) treatment=(0 1)) post
xlincom 4._at-6._at, post

esttab, ci

mat cit`n'= r(coefs)


reg support i.treatment##i.inc3 i.round if topic==`n', cluster(respondent_id)
margins, at(inc3=(1 2 3) treatment=(0 1)) post
xlincom ((4._at-6._at)-(1._at-3._at)), post

esttab, se

mat did`n'= r(coefs)

}
mat ci = ci1\ci2\ci3\ci4\ci5\ci6\ci7\ci8\cit1\cit2\cit3\cit4\cit5\cit6\cit7\cit8

mat list ci

sort respondent_id topic

keep in 1/16

keep topic topic2

g treatment=0 
replace treatment=1 in 9/16

svmat double ci, name(temp)
ren temp1 margin
ren temp2 lb
ren temp3 ub
drop temp4

mat did = did1\did2\did3\did4\did5\did6\did7\did8

mat list did

svmat double did, name(temp)
ren temp1 did_est
ren temp2 did_se
ren temp3 did_p

label define topiclab_alt2 1 "Infrastructure" 2 "Min wage" 3 "Estate tax" 4 "CG tax" 5 "Border sec" 6 "Transgender" 7 "Abortion" 8 "Covid"
label values topic topiclab_alt2

sort topic treatment
g hline=ub+0.03 if treatment==1
replace hline=hline[_n+1] if hline==.

g temp=ub+0.03 if treatment==0
replace temp=temp[_n-1] if temp==.

replace hline=temp if topic==1 | topic==5

drop temp 

g dropl=hline
replace dropl=hline+0.0012 if treatment==0
replace dropl=hline-0.01 if treatment==1

** labels
* slope coefficient
su did_est if treatment==0 & topic==1
local margin_3f : di %9.3f r(mean)
di `margin_3f'
g dydx_t="`margin_3f'" if treatment==0 & topic==1

foreach n of numlist 2/8 {
	su did_est if treatment==0 & topic== `n'
	local margin_3f : di %9.3f r(mean)
	replace dydx_t="`margin_3f'" if treatment==0 & topic== `n'
}


* se
su did_se if treatment==0 & topic== 1
local margin_3f : di %9.3f r(mean)
di `margin_3f'
g se_t="(`margin_3f')" if treatment==0 & topic==1


foreach n of numlist 2/8 {
	su did_se if treatment==0 & topic== `n'
	local margin_3f : di %9.3f r(mean)
	replace se_t="(`margin_3f')" if treatment==0 & topic== `n'
}

replace se_t = subinstr(se_t, " ", "", .)

g lab_t=dydx_t+" "+se_t

replace dydx_t=dydx_t+"*" if did_p<0.05
replace dydx_t=dydx_t+"+" if did_p<0.1 & did_p>0.05

g z=0
g o=1
g x=0.08
g x2=0.14
g y_h=hline+0.04
g y_h2=hline+0.02

twoway ///
(scatter margin treatment if treatment==0, msymbol(O) mcolor(black) lcolor(black)) ///
(scatter margin treatment if treatment==1, msymbol(O) mcolor(gray) lcolor(gray) lpattern(solid)) ///
(rspike lb ub treatment if treatment==0,  lcolor(black)  lwidth(medthick)) ///
(rspike lb ub treatment if treatment==1, lcolor(gray)  lwidth(medthick)) ///
 (line  hline treatment ,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (line  dropl z,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (line  dropl o,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (scatter y_h x2, ms(none) mla(dydx_t) mlabcolor(black) mlabsize(medsmall)) ///
 (scatter y_h2 x, ms(none) mla(se_t) mlabcolor(black) mlabsize(medsmall)), ///
by(topic, r(1) legend(off) note("") title("B: Income", size(large) position(11))) subtitle(,  size(medsmall)) ///
scheme(plotplain) yline(.5) xtick(0 1) xscale(r(-0.2 1.2)) xlabel(0 "Control" 1 "Treat.", labsize(medsmall)  labcolor(gray) tlength(0.5)) ylabel(-0.3(.1)0.3, labsize(medsmall) labcolor(gray) format(%3.1f)) xtitle("", size(medsmall) color(gray)) ytitle("", size(medsmall) color(gray)) xsize(8)


graph export "figureE4b.pdf",  replace
restore





* Figure E4c: female
preserve

foreach n of numlist 1/8 {
reg support i.treatment##i.female i.round if topic==`n', cluster(respondent_id)
margins, at(female=(0 1) treatment=(0 1)) post
xlincom 1._at-2._at, post

esttab, ci

mat ci`n'= r(coefs)

reg support i.treatment##i.female i.round if topic==`n', cluster(respondent_id)
margins, at(female=(0 1) treatment=(0 1)) post
xlincom 3._at-4._at, post

esttab, ci

mat cit`n'= r(coefs)


reg support i.treatment##i.female i.round if topic==`n', cluster(respondent_id)
margins, at(female=(0 1) treatment=(0 1)) post
xlincom ((3._at-4._at)-(1._at-2._at)), post

esttab, se

mat did`n'= r(coefs)

}
mat ci = ci1\ci2\ci3\ci4\ci5\ci6\ci7\ci8\cit1\cit2\cit3\cit4\cit5\cit6\cit7\cit8

mat list ci

sort respondent_id topic

keep in 1/16

keep topic topic2

g treatment=0 
replace treatment=1 in 9/16

svmat double ci, name(temp)
ren temp1 margin
ren temp2 lb
ren temp3 ub
drop temp4

mat did = did1\did2\did3\did4\did5\did6\did7\did8

mat list did

svmat double did, name(temp)
ren temp1 did_est
ren temp2 did_se
ren temp3 did_p

label define topiclab_alt2 1 "Infrastructure" 2 "Min wage" 3 "Estate tax" 4 "CG tax" 5 "Border sec" 6 "Transgender" 7 "Abortion" 8 "Covid"
label values topic topiclab_alt2

sort topic treatment
g hline=ub+0.03 if treatment==1
replace hline=hline[_n+1] if hline==.

g temp=ub+0.03 if treatment==0
replace temp=temp[_n-1] if temp==.

replace hline=temp if topic==1 | topic==6 | topic==7 | topic==8

drop temp 

g dropl=hline
replace dropl=hline+0.0012 if treatment==0
replace dropl=hline-0.01 if treatment==1

** labels
* slope coefficient
su did_est if treatment==0 & topic==1
local margin_3f : di %9.3f r(mean)
di `margin_3f'
g dydx_t="`margin_3f'" if treatment==0 & topic==1

foreach n of numlist 2/8 {
	su did_est if treatment==0 & topic== `n'
	local margin_3f : di %9.3f r(mean)
	replace dydx_t="`margin_3f'" if treatment==0 & topic== `n'
}


* se
su did_se if treatment==0 & topic== 1
local margin_3f : di %9.3f r(mean)
di `margin_3f'
g se_t="(`margin_3f')" if treatment==0 & topic==1


foreach n of numlist 2/8 {
	su did_se if treatment==0 & topic== `n'
	local margin_3f : di %9.3f r(mean)
	replace se_t="(`margin_3f')" if treatment==0 & topic== `n'
}

replace se_t = subinstr(se_t, " ", "", .)

g lab_t=dydx_t+" "+se_t


g z=0
g o=1
g x=0.08
g x2=0.14
g y_h=hline+0.04
g y_h2=hline+0.02

twoway ///
(scatter margin treatment if treatment==0, msymbol(O) mcolor(black) lcolor(black)) ///
(scatter margin treatment if treatment==1, msymbol(O) mcolor(gray) lcolor(gray) lpattern(solid)) ///
(rspike lb ub treatment if treatment==0,  lcolor(black)  lwidth(medthick)) ///
(rspike lb ub treatment if treatment==1, lcolor(gray)  lwidth(medthick)) ///
 (line  hline treatment ,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (line  dropl z,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (line  dropl o,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (scatter y_h x2, ms(none) mla(dydx_t) mlabcolor(black) mlabsize(medsmall)) ///
 (scatter y_h2 x, ms(none) mla(se_t) mlabcolor(black) mlabsize(medsmall)), ///
by(topic, r(1) legend(off) note("") title("C: Female", size(large) position(11))) subtitle(,  size(medsmall)) ///
scheme(plotplain) yline(.5) xtick(0 1) xscale(r(-0.2 1.2)) xlabel(0 "Control" 1 "Treat.", labsize(medsmall)  labcolor(gray) tlength(0.5)) ylabel(-0.3(.1)0.3, labsize(medsmall) labcolor(gray) format(%3.1f)) xtitle("", size(medsmall) color(gray)) ytitle("", size(medsmall) color(gray)) xsize(8)

 graph export "figureE4c.pdf",  replace
restore


* Figure E4d: voter
preserve

foreach n of numlist 1/8 {
reg support i.treatment##i.voter i.round if topic==`n', cluster(respondent_id)
margins, at(voter=(0 1) treatment=(0 1)) post
xlincom 1._at-2._at, post

esttab, ci

mat ci`n'= r(coefs)

reg support i.treatment##i.voter i.round if topic==`n', cluster(respondent_id)
margins, at(voter=(0 1) treatment=(0 1)) post
xlincom 3._at-4._at, post

esttab, ci

mat cit`n'= r(coefs)


reg support i.treatment##i.voter i.round if topic==`n', cluster(respondent_id)
margins, at(voter=(0 1) treatment=(0 1)) post
xlincom ((3._at-4._at)-(1._at-2._at)), post

esttab, se

mat did`n'= r(coefs)

}
mat ci = ci1\ci2\ci3\ci4\ci5\ci6\ci7\ci8\cit1\cit2\cit3\cit4\cit5\cit6\cit7\cit8

mat list ci

sort respondent_id topic

keep in 1/16

keep topic topic2

g treatment=0 
replace treatment=1 in 9/16

svmat double ci, name(temp)
ren temp1 margin
ren temp2 lb
ren temp3 ub
drop temp4

mat did = did1\did2\did3\did4\did5\did6\did7\did8

mat list did

svmat double did, name(temp)
ren temp1 did_est
ren temp2 did_se
ren temp3 did_p

label define topiclab_alt2 1 "Infrastructure" 2 "Min wage" 3 "Estate tax" 4 "CG tax" 5 "Border sec" 6 "Transgender" 7 "Abortion" 8 "Covid"
label values topic topiclab_alt2

sort topic treatment
g hline=ub+0.03 if treatment==1
replace hline=hline[_n+1] if hline==.

g temp=ub+0.03 if treatment==0
replace temp=temp[_n-1] if temp==.

replace hline=temp if topic==2 | topic==4 | topic==7

drop temp 

g dropl=hline
replace dropl=hline+0.0012 if treatment==0
replace dropl=hline-0.01 if treatment==1

** labels
* slope coefficient
su did_est if treatment==0 & topic==1
local margin_3f : di %9.3f r(mean)
di `margin_3f'
g dydx_t="`margin_3f'" if treatment==0 & topic==1

foreach n of numlist 2/8 {
	su did_est if treatment==0 & topic== `n'
	local margin_3f : di %9.3f r(mean)
	replace dydx_t="`margin_3f'" if treatment==0 & topic== `n'
}


* se
su did_se if treatment==0 & topic== 1
local margin_3f : di %9.3f r(mean)
di `margin_3f'
g se_t="(`margin_3f')" if treatment==0 & topic==1


foreach n of numlist 2/8 {
	su did_se if treatment==0 & topic== `n'
	local margin_3f : di %9.3f r(mean)
	replace se_t="(`margin_3f')" if treatment==0 & topic== `n'
}

replace se_t = subinstr(se_t, " ", "", .)

g lab_t=dydx_t+" "+se_t

replace dydx_t=dydx_t+"*" if did_p<0.05
replace dydx_t=dydx_t+"+" if did_p<0.1 & did_p>0.05

g z=0
g o=1
g x=0.08
g x2=0.14
g y_h=hline+0.04
g y_h2=hline+0.02

twoway ///
(scatter margin treatment if treatment==0, msymbol(O) mcolor(black) lcolor(black)) ///
(scatter margin treatment if treatment==1, msymbol(O) mcolor(gray) lcolor(gray) lpattern(solid)) ///
(rspike lb ub treatment if treatment==0,  lcolor(black)  lwidth(medthick)) ///
(rspike lb ub treatment if treatment==1, lcolor(gray)  lwidth(medthick)) ///
 (line  hline treatment ,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (line  dropl z,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (line  dropl o,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (scatter y_h x2, ms(none) mla(dydx_t) mlabcolor(black) mlabsize(medsmall)) ///
 (scatter y_h2 x, ms(none) mla(se_t) mlabcolor(black) mlabsize(medsmall)), ///
by(topic, r(1) legend(off) note("") title("D: Voter", size(large) position(11))) subtitle(,  size(medsmall)) ///
scheme(plotplain) yline(.5) xtick(0 1) xscale(r(-0.2 1.2)) xlabel(0 "Control" 1 "Treat.", labsize(medsmall)  labcolor(gray) tlength(0.5)) ylabel(-0.3(.1)0.3, labsize(medsmall) labcolor(gray) format(%3.1f)) xtitle("", size(medsmall) color(gray)) ytitle("", size(medsmall) color(gray)) xsize(8)

graph export "figureE4d.pdf",  replace
restore
